<template>
  <div style="margin-top:18px">
    <setting-card :filterData='filterData' @goSetting='goSetting'></setting-card>
    <div v-show="contentShow"
           style="text-align: center;margin-top:114px;">
        <img :width="320"
             :height="240"
             :src="error">
      </div>
  </div>
</template>

<script>
import error from '@/assets/images/error-page/error.svg'
import SettingCard from '@/view/components/setting-card/setting-card.vue'
import { getDicQuery } from '@/api/setting'
export default {
  name: 'shopmsg-setting',
  components: {
    SettingCard
  },
  watch: {
    '$route' (newRoute) {
      if (newRoute.name === 'shopmsg-setting') {
        this.getDicQuery()
      }
    }
  },
  created () {
    this.getDicQuery()
  },
  methods: {
    goSetting (fid) {
      this.$router.push({
        name: 'global_setting_page_' + fid
      })
    },
    getDicQuery () {
      this.dataList = this.allData.filter(item => {
        return this.hasPermission(item.sn)
      })
      let keys = this.dataList.map(item => {
        return item.code
      })
      if (this.dataList.length > 0) {
        getDicQuery({
          'merchantId': this.$store.state.user.merchantId,
          'msType': '0',
          'dictKeys': keys.join(',')
        }).then(res => {
          if (res.data.status === 200) {
            res.data.data.forEach(data => {
              for (var p in data) {
                this.dataList.forEach(item => {
                  if (p === item.code) {
                    item['updateTime'] = data['updateTime']
                    item['dictValue'] = data[p]
                  }
                })
                this.filterData = this.dataList
              }
            })
          } else {
            this.$Message.error(res.data.message + '服务器' + res.data.status)
          }
        })
      } else {
        this.contentShow = true
      }
    }
  },
  data () {
    return {
      contentShow: false,
      error: error,
      filterData: [],
      dataList: [],
      allData: [
        {
          'code': 'shopType',
          'description': '设置门店属于直营、加盟等属性',
          'manner': 1,
          'position': null,
          'name': '门店类型',
          'updateTime': null,
          'dictValue': null,
          'sn': 'moms:globalsetting:shopinfoconfig',
          'fid': 31
        },
        {
          'code': 'shopStatus',
          'description': '设置门店为营业中、待开业、停业等状态',
          'manner': 1,
          'position': null,
          'name': '门店状态',
          'updateTime': null,
          'dictValue': null,
          'sn': 'moms:globalsetting:shopinfoconfig',
          'fid': 32
        },
        {
          'code': 'targetFirmwareVersion',
          'description': '已有大玩家、PLAY1、蜜柚品牌，可新增',
          'manner': 1,
          'position': null,
          'name': '品牌',
          'updateTime': null,
          'dictValue': null,
          'sn': 'moms:globalsetting:shopinfoconfig',
          'fid': 33
        },
        {
          'code': 'shopLevel',
          'description': '已有超A、A、B、C、D等级，可新增',
          'manner': 1,
          'position': null,
          'name': '门店等级',
          'updateTime': null,
          'dictValue': null,
          'sn': 'moms:globalsetting:shopinfoconfig',
          'fid': 34
        },
        {
          'code': 'projectType',
          'description': '选择门店所属万达或非万达项目，可编辑',
          'manner': 1,
          'position': null,
          'name': '项目类型',
          'updateTime': null,
          'dictValue': null,
          'sn': 'moms:globalsetting:shopinfoconfig',
          'fid': 35
        }
      ]
    }
  }
}
</script>
